package com.leyou.item.dto;

import com.leyou.common.dto.BaseDTO;
import com.leyou.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class BrandDto extends BaseDTO {
    private Long id;
    private String name;
    private String image;
    private Character letter;
    private List<Long> categoryIds;//加了分类id集合

    public BrandDto(BaseEntity entity) {
        super(entity);
    }

    /**
     * 将Entity集合转为DTO集合
     * @param list Entity对象的集合
     * @param <T>  Entity的类型
     * @return DTO集合
     */
    public static <T extends BaseEntity> List<BrandDto> convertEntityList(Collection<T> list) {
        if (list == null) {
            return Collections.emptyList();
        }
        return list.stream().map(BrandDto::new).collect(Collectors.toList());
    }

}
